/*************************************************************************
    > File Name: reg2nfa.h
    > Author: liujing
    > Mail: jingliu.cs@gmail.com 
    > Created Time: 2014年10月21日 星期二 00时01分25秒
 ************************************************************************/

#ifndef _REG_2_NFA_
#define _REG_2_NFA_

#include "nfa.h"
#include <stack>
#include <iostream>
#define TRUE 1
#define FALSE 0


struct GraphHeadTail{
	int start;	//the start state of NFA
	int end;	//the end state of NFA
};

class RegToNFA{
public:
	RegToNFA(void);
	~RegToNFA(void);
public:
	RegToNFA(string reg);
	Graph* graph;
	string reg;
	void createNFA();
	bool isOperator(wchar_t ch);
	stack<wchar_t> operatorStack;
	stack<GraphHeadTail> graphStack;
	GraphHeadTail ght1,ght2;	//temp variable to store the two are poped
	void basicOperate(GraphNode* n1,GraphNode* n2,int i);
	void repeatOperate();
	void choiceOperate();
	void appositeOperate();
	int temp;
	void printGraphLink(void);
	bool isVisited(GraphNode* graphNode);
	int findMax(int y,int x);
	GraphNode* findGraphNode(int ID);
	vector<GraphNode*> isVisitedGraphNodes;
};

#endif
